<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>库存盘点</title>
	<meta name="renderer" content="webkit">
	<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
	<style>
		.layui-border{
			margin-bottom: 15px;
			border: 1px solid #e6e6e6;
			padding: 10px 20px 5px 20px;
			color: #6b6b6b;
		}

		.table-search-fieldset {
			margin: 0;
			border: 1px solid #e6e6e6;
			color: #6b6b6b;
		}
		.layui-text{
			display: inline-block;
			margin-right: 25px;
		}
		.layui-colla-item{
			width:150px;
		}
	</style>
</head>
<body>
<div class="layui-tab">
	<ul class="layui-tab-title">
		<li class="layui-this">盘点列表</li>
	</ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show">
			<div class="layui-border" id="start">
				<button class="layui-btn  layui-btn-sm">开始盘点</button>
			</div>
			 <!--开始盘点菜单 -->
			<div style="display: none;" id="startCounting">
				<div style="display:block;" id="firstStep">
					<div style="color: red;margin-top: 20px;margin-left: 30px;">第一步，根据查询条件，查询出相应的盘点单，然后在列表中选择要盘点的单号，可以多选，但至少要选择一个盘点单。</div>
					<fieldset class="table-search-fieldset">
						<legend>选择盘点单</legend>
						<!--<div class="layui-form layui-inline">-->
							<!--<div class="layui-inline">-->
								<!--<label class="layui-form-label">仓库名称:</label>-->
								<!--<div class="layui-input-inline">-->
									<!--<select name="modules" lay-verify="required" lay-search="">-->
										<!--<option value="">所有仓库</option>-->
										<!--<option value="1">主仓库</option>-->
										<!--<option value="2">酒库</option>-->
										<!--<option value="3">饮料库</option>-->
									<!--</select>-->
								<!--</div>-->
							<!--</div>-->
							<!--<div class="layui-inline">-->
								<!--<label class="layui-form-label">操作员:</label>-->
								<!--<div class="layui-input-inline">-->
									<!--<select name="operator" lay-verify="required" lay-search="">-->
										<!--<option value="">所有操作员</option>-->
										<!--<option value="1">admin</option>-->
										<!--<option value="2">02</option>-->
										<!--<option value="3">pos</option>-->
										<!--<option value="2">04</option>-->
									<!--</select>-->
								<!--</div>-->
							<!--</div>-->
							<!--<button class="layui-btn ">查询</button>-->
						<!--</div>-->
						<table class="layui-hide" id="counting" lay-filter="counting"></table>
						<div style="color: #0084E9;margin-top: 10px;margin-bottom: 10px;">共选择了<span id="ling">0</span>个盘点单</div>
						<form>
						<button type="button" class="layui-btn " id='nextBtn'>下一步</button>
						<button type="button" class="layui-btn" id="tuis1">退出</button>
						</form>
					</fieldset>
				</div>
                <div style="display:none" id="secondStep">
                    <div style="color: red;margin-top: 16px;margin-left: 30px;">第二步:根据第一步选择的盘点单，汇总得到列表中所有的盘点商品</div>
                    <fieldset class="layui-elem-field layui-field-title" style="padding: 0 20px 0 20px">
                        <legend style="font-size: 20px">所有盘点商品（共选择了<span id="towpd">1</span>个盘点单。下列为已盘点单的汇总记录）</legend>
                        <table  class="layui-hide" id="commoditySummary" lay-filter="commoditySummary"></table>
                        <form>
                            <button type="button" class="layui-btn " id='lastStep'>上一步</button>
                            <button type="button" class="layui-btn " id='nextStep'>下一步</button>
                            <button type="button" class="layui-btn" id="tuis2">退出</button>
                        </form>
                    </fieldset>
                </div>
                <div style="display:none" id="tree">
                    <div style="color: red;margin-top: 16px;margin-left: 30px;">第三步:盘点数量-库存数量=差异数量，在列表中可以看到所有盘点过的商品差异数量，确定数量没有错误时可以点击“修正库存”按钮进行库存修正，库存修正后将无法恢复。请在修正库存之前备份好数据库。</div>
                    <fieldset class="layui-elem-field layui-field-title" style="padding: 0 20px 0 20px">
                        <legend style="font-size: 20px">盘点差异表</legend>
						<input type="hidden" value="">
                        <table  class="layui-hide" id="difference" lay-filter="difference"></table>
                        <form>
                            <button type="button" class="layui-btn " id="previousStep">上一步</button>
                            <button type="submit" class="layui-btn " id="fixedInventory">修正库存</button>
                            <button type="button" class="layui-btn " id="tuis3">退出</button>
                        </form>
                    </fieldset>
                </div>
			</div>
			<fieldset class="table-search-fieldset">
				<legend>盘点单列表(列表中显示的是所有未修正库存前的盘点单)</legend>
				<script type="text/html" id="toolbarDemo">
					<div class="layui-btn-container">
						<button class="layui-btn  layui-btn-sm" id='inventpry'> 新增盘点单 </button>
						<button class="layui-btn  layui-btn-sm data-delete-btn" lay-event="delete">删除盘点单 </button>
					</div>
				</script>
				<div style="display: none;padding: 10px;" id='newInventory'>
					<fieldset class="layui-elem-field">
						<legend>盘点信息</legend>
						<div class="layui-field-box">
							<form class="layui-form" action="">
								<div class="layui-form">
									<div class="layui-inline" style="margin-left: 65px;">盘点单号：<span id="stochasticpd">11111111111111</span></div>
									<div class="layui-inline">
										<label class=" layui-form-label">盘点仓库</label>
										<div class="layui-input-inline" id="pdck">
											<select id="modules" name="modules" lay-verify="required" lay-search="" lay-filter="ck">
												<option selected="selected" disabled="disabled"  style='display: none' value=''></option>
											</select>
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">盘点日期</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" id="test3" placeholder="yyyy-MM-dd">
										</div>
									</div>
									<div class="layui-inline">操作员:admin</div>
									<div class="layui-form-item " style="margin-top: 10px;">
										<label class="layui-form-label">备注</label>
										<div class="layui-input-block" style="border-bottom: 1px solid #D2D2D2;">
											<input id="comment" style="border:none;" type="text" name="title" lay-verify="title" autocomplete="off" placeholder=""
												   class="layui-input">
										</div>
									</div>
								</div>
							</form>
							<div class="layui-inline" style="color: red;">提示:盘点前请选择仓库。盘点中不能更换仓库和日期。在没有修正库存之前请勿有采购进货、销售等能改变库存数里的操作，不然会造成库存数里不准。</div>
						</div>
					</fieldset>
					<fieldset class="layui-elem-field" style="width:620px;float: left;margin-right: 15px;">
						<legend>库存商品</legend>
							<div class="layui-form-item" style="margin-left: 30px;">
								<label class="layui-form-label">商品信息</label>
								<div class="layui-input-inline" style="margin-right: 20px;">
									<input style="width: 200px;" type="text" name="title" lay-verify="title" autocomplete="off"
										   class="layui-input">
								</div>
								<div class="layui-input-inline" style="margin-top: 5px;">
									<button class="layui-btn layui-btn-sm " id="qd">确定</button>
								</div>
							</div>
						<div class="layui-tab">
							<ul class="layui-tab-title">
								<li class="layui-this">商品清单</li>
								<li>商品列表</li>
							</ul>
							<div class="layui-tab-content" style="padding: 0px;height: 90px;">
								<div class="layui-tab-item layui-show" style="height: 70px;width: 616px;">
									<!--商品清单表格-->
									<table class="layui-hide" id="commodityList" lay-filter="currentTableFilter"lay-data="{id: 'idTest'}"></table>
								</div>
								<div class="layui-tab-item" style="">
									<div id="test4" class="demo-tree" style="float: left;width: 150px;height: 420px;border: 1px solid #F1F1F1;"></div>
									<div class="layui-input-inline" style="width: 440px;float: left;">
										<!--商品列表-->
										<table class="layui-hide" id="spllxx"></table>
									</div>
								</div>
							</div>
						</div>
					</fieldset>
					<fieldset class="layui-elem-field" style="width: 620px;float: left;">
						<legend>已盘商品</legend>
						<form>
						<div class="layui-col-md6 layui-input-inline" style="height: 95px;width: 100%;border-bottom:1px solid #E2E2E2 ;">
							<div class="layui-panel" style="margin-top:20px;margin-left: 200px;border: none;box-shadow:none">
								<button type="button" class="layui-btn layui-btn-sm" id="amend">修改</button>
								<button type="button" class="layui-btn layui-btn-sm " id="dele" lay-event="de">删除</button>
								<button type="submit" class="layui-btn layui-btn-sm " id="tuichu">退出</button>
							</div>
						</div>
						</form>
						<div class="layui-input-inline" style="width: 480px;">
							<table class="layui-hide" id="ypsp" lay-filter="ypsp"></table>
						</div>
					</fieldset>
				</div>
			<!--商品详细信息弹窗-->
				<div style="display: none;" id="entryGoods">
					<form class="layui-form" action="">
					<div class="layui-tab" >
						<ul class="layui-tab-title">
							<li class="layui-this">商品库存信息</li>
							<li>商品信息</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item layui-show">
								<div class="layui-form">
									<table class="layui-table" id="inventoryInformation" lay-filter="inventoryInformation">

									</table>
								</div>
							</div>
							<div class="layui-tab-item" style="height:200px">
									<div class="layui-item" style="float: left;margin: 0 20px 10px 30px">
										<label class="layui-label">商品编号</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=50 id="bh"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left;margin-bottom: 10px" >
										<label class="layui-label">商品名称</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=120 id="mc"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left;margin: 0 20px 10px 30px" >
										<label class="layui-label">单位</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=30 id="dw"disabled="true">
										</div>
									</div>

									<div class="layui-item" style="float: left;margin: 0 20px 10px 30px">
										<label class="layui-label">规格型号</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=80 id="xh"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left;margin: 0 20px 10px 30px">
										<label class="layui-label">药剂类型</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=80 id="lx"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left;margin:0 20px 10px 0px">
										<label class="layui-label">当前库存</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=80 id="kc"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left;;margin: 0 20px 0 30px">
										<label class="layui-label">生产厂商</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=80 id="cs"disabled="true">
										</div>
									</div>
									<div class="layui-item" style="float: left">
										<label class="layui-label">备注</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" width=80 id="bz"disabled="true">
										</div>
									</div>
							</div>
						</div>
					</div>
					<div class="layui-tab">
						<ul class="layui-tab-title">
							<li class="layui-this">请在下面表格中输入您的盘点数量</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item layui-show">
								<div class="layui-form">
									<table class="layui-table" id="inventoryInformationNum" lay-filter="inventoryInformationNum">

									</table>
								</div>
							</div>
						</div>
					</div>
						<button type="button" class="layui-btn" lay-filter="bth" style="margin: 0 100px 0 200px;" id="increase">确定 </button>
						<button type="button" class="layui-btn" id="ts">退出</button>
					</form>
				</div>
				<table class="layui-hide" id="currentTableId" lay-filter="currentTableId"></table>

				<script type="text/html" id="currentTableBar">
					<a class="layui-btn  layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
					<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
				</script>
				<script type="text/html" id="toolbar">

					<div class="layui-btn-container">
						<div class="layui-text layui-sp">盘点商品明细</div>
						<div class="layui-text" >盘点单号:<span id="invenum"></span></div>
						<button type="button" class="layui-btn  layui-btn-sm data-add-btn" id="addsp">新增商品 </button>
						<button lay-event="delete" type="button" class="layui-btn  layui-btn-sm data-delete-btn " id="delcommodity">删除商品</button>
					</div>

				</script>
				<table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
			</fieldset>
		</div>
	</div>
</div>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['laydate', 'form', 'table', 'jquery', 'element', 'layer','tree', 'laydate', 'tableSelect','util'], function() {
        var form = layui.form,
            laydate = layui.laydate,
            table = layui.table,
            layer = layui.layer,
            element = layui.element,
            laydate = layui.laydate,
            tree = layui.tree,
            $ = layui.jquery,
            util = layui.util;
            tableSelect = layui.tableSelect;
        element.on('collapse(test)', function(data) {
            layer.msg('展开状态：' + data.show);
        });
		var depId;
        $.ajax({
            url: '/searchDepotInfo',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                $.each(data, function (index, item) {
                    // 下拉菜单里添加元素
                    $('#modules').append(new Option(item.depotName,item.depotId));
                });
                //重新渲染 固定写法
                layui.form.render("select");
            }
        });
//日期是否补0操作
        function isAddZero(num){
            return num<10 ? "0"+num : num;
        }
//生成随机报损/报溢编号
        function createSalesOrdId(){
            var date = new Date();
            var y = isAddZero(date.getFullYear()); //获取当前年
            var month = isAddZero(date.getMonth() + 1); //获取当前月
            var d = isAddZero(date.getDate()); //获取当前日
            var h = isAddZero(date.getHours());//获取当前小时数(0-23)
            var m = isAddZero(date.getMinutes());//获取当前分钟数(0-59)
            var s = isAddZero(date.getSeconds());//获取当前秒
            return "PD"+y+month+d+h+m+s;
        }
        function isAdd(num){
            return num<10 ? "0"+num : num;
        }
//生成随机报损/报溢编号
        function createSalesOrd(){
            var date = new Date();
            var y = isAddZero(date.getFullYear()); //获取当前年
            var month = isAddZero(date.getMonth() + 1); //获取当前月
            var d = isAddZero(date.getDate()); //获取当前日
            var h = isAddZero(date.getHours());//获取当前小时数(0-23)
            var m = isAddZero(date.getMinutes());//获取当前分钟数(0-59)
            var s = isAddZero(date.getSeconds());//获取当前秒
            return "PDMX"+y+month+d+h+m+s;
        }
        form.on('select',function (data) {
            var	ckName = data.value;
            table.reload('commodityList', {
                url:"/selectCheckProcess?ck="+ckName,
                page: {
                    curr: 1
                }, done: function (res, curr, count) {
                    $('.layui-table-view[lay-id="commodityList"]')
                        .children('.layui-table-box')
                        .children('.layui-table-body')
                        .find('table tbody tr[data-index="0"]').click();
                },
            }, 'data');
            return false;
        })
		 var start=false;
        var array=[];
        table.on('checkbox(counting)', function(obj){
            var checkStatus = table.checkStatus('counting');
            $("#ling").text(checkStatus.data.length);
            if(obj.checked == true){
                array.push(obj.data.invCheckId);
			}else{
                array.splice($.isArray(obj.data.invCheckId,array),1)
			}

        });
        var invId;
        //选择完盘点单后选择点击下一步
        $('#nextBtn').click(function() {
            var checkStatus = table.checkStatus('counting');
            if ( 0 == checkStatus.data.length ) {
                layer.confirm('请选择盘点单', function (index) {
                    layer.close(index);
                });
			} else {
                $('#firstStep').css('display','none');
                $('#secondStep').show();
			}
            $("#towpd").text(checkStatus.data.length);
			 invId = "";
			for ( var i in array ) {
                invId += array[i];
                if ( i != array.length - 1 && array.length >=2 ) {
                    invId += ',';
				}
			}
            $.post("/selectSecondStep",{invId:invId},function (data) {
				table.reload('commoditySummary',{
				    data: JSON.parse(data).data
				})
			})
        })
        $("#nextStep").click(function () {
            $('#tree').show();
            $('#secondStep').hide();
            $.post("/selectTreeStep", function (data) {
                table.reload('difference', {
                    data: JSON.parse(data).data
                })
            })
        })
        //第二步上一步按钮
        $('#lastStep').click(function () {
            $('#firstStep').show();
            $('#secondStep').hide();
        })
        //第三步返回上一步
        $("#previousStep").click(function () {
            $("#tree").hide();
            $('#secondStep').show();
        })
        var now=new Date();
        //常规用法
        laydate.render({
            elem: '#test1',
            value:now
        });
        laydate.render({
            elem: '#test2',
            value:now
        });
        laydate.render({
            elem: '#test3',
            value:now
        });

        var ypsdsum;
        table.render({
            elem: '#inventoryInformation',
			totalRow:true,
            cols: [
                [{
                    field: '序号',
                    width: 110,
                    title: '序号',
					totalRowText:"合计",
                    type:'numbers'
                }, {
                    field: 'inveDescBatchNum',
                    width: 140,
                    title: '批号'
                },
                    {
                        field: 'inveDescValidityDate',
                        width: 120,
                        title: '有效期',
                        templet:"<div>{{layui.util.toDateString(d.userBirthday, 'yyyy-MM-dd')}}</div> "
                    },
                    {
                        field: 'inveDescInventoryNum',
                        width: 120,
                        title: '数量',
                        totalRow:true
                    },
                ]
            ],
            skin: 'line'
        });

        var inveInfo = [];
        table.render({
            elem: '#inventoryInformationNum',
            escape: true,
            cols: [
                [{
                    field: '序号',
                    width: 110,
                    title: '序号',
                    type:'numbers'
                }, {
                    field: 'inveDescBatchNum',
                    width: 140,
                    title: '批号'
                },
                    {
                        field: 'inveDescValidityDate',
                        width: 120,
                        title: '有效期',
                        templet:"<div>{{layui.util.toDateString(d.userBirthday, 'yyyy-MM-dd')}}</div> "
                    },
                    {
                        field: '',
                        width: 120,
                        title: '数量',
                        totalRow:true,
                        edit: 'text'
                    },
                ]
            ],
            skin: 'line',
            done: function (res) {
                inveInfo=res.data;
            }
        });
        var descInfo=[];
        table.render({
            elem: '#difference',
            data:[],
            cols: [
                [{
                    field: 'proId',
                    width: 110,
                    title: '商品编号'
                }, {
                    field: 'invCheckDescProName',
                    width: 140,
                    title: '商品名称'
                },
                    {
                        field: 'invCheckDescProUnit',
                        width: 120,
                        title: '单位'
                    },
                    {
                        field: 'invCheckDescBatchNum',
                        width: 100,
                        title: '批号'
                    },
                    {
                        field: 'invCheckDescModel',
                        width: 120,
                        title: '规格型号'
                    },
                    {
                        field: 'invCheckDescCheckNum',
                        width: 130,
                        title: '盘点数量'
                    },
                    {
                        field: 'invCheckDescInventoryNum',
                        width: 130,
                        title: '当前库存量'
                    },
                    {
                        field: 'quantityVariance',
                        width: 130,
                        title: '差异数量'
                    },
                    {
                        field: 'depotName',
                        width: 120,
                        title: '所在仓库'
                    },
                ]
            ],
            limits: [9, 15, 20, 25, 50, 100],
            limit: 15,
            skin: 'line',
            done: function (res) {
                descInfo=JSON.stringify(res.data).replace('[','').replace(']','');
            }
        });
        //开始盘点中所有盘点的商品
        table.render({
            elem: '#commoditySummary',
            data:[],
            cols: [
                [{
                    field: 'proId',
                    width: 110,
                    title: '商品编号'
                }, {
                        field: 'invCheckDescProName',
                        width: 140,
                        title: '商品名称'
                    },
                    {
                        field: 'invCheckDescBatchNum',
                        width: 100,
                        title: '批号'
                    },
                    {
                        field: 'invCheckDescProUnit',
                        width: 120,
                        title: '单位'
                    },
                    {
                        field: 'invCheckDescModel',
                        width: 120,
                        title: '规格型号'
                    },
                    {
                        field: 'invCheckDescCheckNum',
                        width: 130,
                        title: '盘点数量'
                    },
                    {
                        field: 'depotName',
                        width: 120,
                        title: '所在仓库'
                    },
                ]
            ],
            limits: [9, 15, 20, 25, 50, 100],
            limit: 15,
            skin: 'line'
        });
        table.render({
            elem: '#spllxx',
            url: '../../api/table.json',
            width: 470,
            cols: [
                [{field: 'proId', title: '商品编号', width:90, align: "center"}
                    ,{field: 'inveDescName', title: '商品名称', width:100, align: "center"}
                    ,{field: 'inveDescUnit', title: '单位', width:70, align: "center"}
                    ,{field: 'inveDescSize', title: '规格', width: 90, align: "center"}
                    ,{field: 'inveDescInventoryNum', title: '库存数', width: 90, sort: true, align: "center"}
                    ,{field: 'inveDescManufacturer', title: '生产商', width: 120, align: "center"}
                ]
            ],
            limits: [9, 15, 20, 25, 50, 100],
            limit: 15,
            skin: 'line'
        });
        table.render({
            elem: '#ypsp',
            width: 620,
            url:"/searchStatementyp",
			done: function (res, curr, count) {
            ypsdsum=count;
                $('.layui-table-view[lay-id="currentTable"]')
                    .children('.layui-table-box')
                    .children('.layui-table-body')
                    .find('table tbody tr[data-index="0"]').click();
        },
            cols: [
                [{
                    field: 'proId',
                    width: 90,
                    title: '商品编号'
                },
                    {
                        field: 'invCheckDescProName',
                        width: 90,
                        title: '商品名称'
                    },
                    {
                        field: 'invCheckDescProUnit',
                        width: 75,
                        title: '单位'
                    },
                    {
                        field: 'invCheckDescCheckNum',
                        width: 110,
                        title: '盘点数量'
                    },
                    {
                        field: 'invCheckDescInventoryNum',
                        width: 110,
                        title: '库存数量'
                    },
                    {
                        field: 'invCheckId',
                        width: 150,
                        title: '盘点单号'
                    },
                ]
            ],
            limits: [9, 15, 20, 25, 50, 100],
            limit: 15,
            skin: 'line'
        });
        //商品清单
        table.render({
            elem: '#commodityList',
            url: '/selectCheckProcess',
            cols: [
                [{
                    field: 'proId',
                    width: 110,
                    title: '商品编号',
                    align: 'center'
                }, {
                    field: 'inveDescName',
                    width: 140,
                    title: '商品名称',
                    align: 'center'
                }, {
                    field: 'inveDescType',
                    width: 120,
                    title: '单位',
                    align: 'center'
                }, {
                    field: 'inveDescSize',
                    width: 130,
                    title: '规格型号',
                    align: 'center'
                }, {
                    field: 'inveDescInventoryNum',
                    title: '库存数量',
                    width: 130,
                    align: 'center'
                } //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
                ]
            ]
        });
        table.render({
            elem: '#counting',
            url: '/selectselectInventorySurplus',
            cols: [
                [{
                    type: "checkbox",
                    width: 30
                },
                    {
                        field: 'invCheckId',
                        width: 120,
                        title: '盘点单号'
                    },
                    {
                        field: 'invCheckDate',
                        width: 120,
                        title: '日期',
                        templet:"<div>{{layui.util.toDateString(d.userBirthday, 'yyyy-MM-dd')}}</div> "
                    },
                    {
                        field: 'depotId',
                        width: 110,
                        title: '仓库名称'
                    },
                    {
                        field: 'empId',
                        width: 120,
                        title: '操作员'
                    },
                    {
                        field: 'invCheckProBar',
                        width: 120,
                        title: '商品条数'
                    },
                    {
                        field: 'invCheckProNum',
                        width: 120,
                        title: '商品数量'
                    },
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        table.render({
            elem: '#currentTableId',
            url: '/selectTakeStock',
            width: 1270,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }], done: function (res, curr, count) {
                $('.layui-table-view[lay-id="currentTableId"]')
                    .children('.layui-table-box')
                    .children('.layui-table-body')
                    .find('table tbody tr[data-index="0"]').click();
            },
            cols: [
                [
                    //{type: "checkbox", width: 50},
                    {
                        field: 'invCheckId',
                        width: 100,
                        title: '盘点单号',

                    },
                    {
                        field: 'invCheckDate',
                        width: 130,
                        title: '日期',
                        templet:"<div>{{layui.util.toDateString(d.userBirthday, 'yyyy-MM-dd')}}</div> "
                    },
                    {
                        field: 'depotId',
                        width: 100,
                        title: '仓库名称',

                    },
                    {
                        field: 'empId',
                        width: 100,
                        title: '操作员'
                    },
                    {
                        field: 'invCheckProBar',
                        width: 100,
                        title: '商品条数',

                    },
                    {
                        field: 'invCheckProNum',
                        width: 100,
                        title: '商品数量',

                    },
                    {
                        field: 'invCheckProComment',
                        Width: 100,
                        title: '备注'
                    },
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        table.render({
            elem: '#currentTable',
            url: '/selectInventoryCheckDesc',
            toolbar: '#toolbar',
            width:1270,
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    //{type: "checkbox", width: 50},
                    {
                        field: 'proId',
                        width: 100,
                        title: '商品编号',

                    },
                    {
                        field: 'invCheckDescProName',
                        width: 150,
                        title: '商品名称'
                    },
                    {
                        field: 'invCheckDescProType',
                        width: 100,
                        title: '商品类别',

                    },
                    {
                        field: 'invCheckDescProUnit',
                        width: 80,
                        title: '单位'
                    },
                    {
                        field: 'invCheckDescModel',
                        width: 100,
                        title: '规格型号',

                    },
                    {
                        field: 'invCheckDescManufacturer',
                        width: 100,
                        title: '生产厂商',

                    },
                    {
                        field: 'invCheckDescInventoryNum',
                        Width: 80,
                        title: '库存数量'
                    },
                    {
                        field: 'invCheckDescBatchNum',
                        Width: 80,
                        title: '商品批号'
                    },
                    {
                        field: 'invCheckDescCheckNum',
                        Width: 80,
                        title: '盘点数量'
                    },
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        table.render({
            elem: '#current',
            url: '../../api/table.json',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    //{type: "checkbox", width: 50},
                    {
                        field: 'id',
                        width: 100,
                        title: '盘点单号',

                    },
                    {
                        field: 'username',
                        width: 150,
                        title: '盘点日期'
                    },
                    {
                        field: 'sex',
                        width: 100,
                        title: '商品编号',

                    },
                    {
                        field: 'city',
                        width: 80,
                        title: '商品名称'
                    },
                    {
                        field: 'experience',
                        width: 80,
                        title: '商品批号',

                    },
                    {
                        field: 'score',
                        width: 80,
                        title: '有效期',
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '单位'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '规格型号'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '盘点数量'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '库存数量'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '数量差值'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '金额差值'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '仓库名称'
                    },
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        table.render({
            elem: '#inventory',
            url: '../../api/table.json',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    //{type: "checkbox", width: 50},
                    {
                        field: 'id',
                        width: 100,
                        title: '商品编号',

                    },
                    {
                        field: 'username',
                        width: 130,
                        title: '商品名称'
                    },
                    {
                        field: 'sex',
                        width: 100,
                        title: '商品编号',

                    },
                    {
                        field: 'city',
                        width: 80,
                        title: '商品名称'
                    },
                    {
                        field: 'experience',
                        width: 80,
                        title: '商品批号',

                    },
                    {
                        field: 'score',
                        width: 80,
                        title: '有效期',

                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '单位'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '规格型号'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '盘点数量'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '库存数量'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '数量差值'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '金额差值'
                    },
                    {
                        field: 'aa',
                        Width: 80,
                        title: '仓库名称'
                    },
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        // 监听搜索操作
        function startCountingInfo() {
            layer.open({
                type: 1,
                title: '<h2 style="color: #1E9FFF;font-weight: bold;">盘盈盘亏<h2>',
                scrollbar: false, //屏蔽浏览器滚动条
                area: ['60%', '100%'],
                content: $('#startCounting')
            });
        }
        var inveDescBatchNum;
        var inveDescValidityDate;
        var inveDescInventoryNum;
        var oDate;
        var invCheckDescBatchNum;
        var proId;
        var postil;
        //点击商品清单
        table.on('row(currentTableFilter)', function(obj){
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
            inveDescBatchNum=obj.data.inveDescBatchNum;
            inveDescValidityDate=getTimeDate(obj.data.inveDescValidityDate);
            inveDescInventoryNum=obj.data.inveDescInventoryNum;
            proId=obj.data.proId;
            postil=obj.data.inveDescPostil;
            $('#bh').val(obj.data.proId);
            $('#mc').val(obj.data.inveDescName);
            $('#dw').val(obj.data.inveDescUnit);
            $('#xh').val(obj.data.inveDescSize);
            $('#lx').val(obj.data.inveDescPostil);
            $('#kc').val(obj.data.inveDescInventoryNum);
            $('#cs').val(obj.data.inveDescManufacturer);
            $('#bz').val(obj.data.inveDescComment);
            id=obj.data.inveDescId;
            var d= new Date();
            var arrayObj = new Array(obj.data);
            $('#invenum').text(obj.data.invCheckId);
        });
        var checkid;
        var invCheckDescId
        table.on('row(currentTableId)', function(obj){
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
        	checkid=obj.data.invCheckId;
            table.reload('currentTable', {
				url:"/selectInventoryCheckDesc?checkid="+checkid,
                page: {
                    curr: 1
                }, done: function (res, curr, count) {
                    exprotDate=res.data;
                    $('.layui-table-view[lay-id="currentTable"]')
                        .children('.layui-table-box')
                        .children('.layui-table-body')
                        .find('table tbody tr[data-index="0"]').click();
                },
            }, 'data');
            return false;
        });
        //删除盘点单
        table.on('toolbar(currentTableId)', function (obj) {
            if (obj.event === 'delete') {
                layer.confirm('是否删除该盘点单据', function (index) {
                    $.post("/deleteInventoryCheckList",{checkid:checkid},function (data) {
                        layer.close(index);
                        location.reload(true);
                        table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                            , where: {
                            }
                        }, 'data');
                        return false;
                    })
                });
            }
        })
        var checkid;
		table.on('row(currentTable)', function(obj){
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
            invCheckDescId=obj.data.invCheckDescId;

        });
		$("#tuis1").click(function () {
            layer.close(layer.index);
        })
        $("#tuis2").click(function () {
            layer.close(layer.index);
        })
        $("#tuis3").click(function () {
            layer.close(layer.index);
        })
        //删除盘点商品
        table.on('toolbar(currentTable)', function (obj) {
            if (obj.event === 'delete') {
                layer.confirm('是否删除商品。', function (index) {
                    $.post("/deleteInventoryCommodity",{invCheckDescId:invCheckDescId,checkid:checkid},function (data) {
                        layer.close(index);
                       location.reload(true);
                     })
				});
            }
        })
        function getTimeDate(date) {
            var date = new Date(date);
            var year = date.getFullYear();
            var moth = date.getMonth() + 1;
            var day = date.getDate();
            var hour = date.getHours();
            var miute = date.getMinutes()
            var secoud = date.getMilliseconds();
            return year + '-' + moth + '-' + day;
        }
        //修改盘点数量
        $( "input[type='text']" ).bind( 'input propertychange' , function (){
            var  val = $( this ).val();
            $('.slbh').html(val);
        })
        $('#start').click(function() {
            startCountingInfo();
        })
     	//新增盘点单按钮
		//修改盘点数量
		var checkNum=[];
        table.on('edit(inventoryInformationNum)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
			checkNum.push(value);
            var indexNum = obj.tr.attr('data-index');
            inveInfo[indexNum].inveDescComment = value;
            inveInfo[indexNum].invCheckDescId=createSalesOrd();
        });
        var sta;
        //录入库存商品
        $('#qd').click(function(obj) {
            sta=1;
            entryGoods();
            $(".ph").html(inveDescBatchNum);
            $(".yxq").html(inveDescValidityDate);
            $(".num").html(inveDescInventoryNum);
            if(sta==1){
                table.reload('inventoryInformation',{
                    url:"/searchDescId?proId="+proId,
                })
                table.reload('inventoryInformationNum',{
                    url:"/searchDescIdd?proId="+proId,
                })
            }
        })
        var ypproId;
        table.on('row(ypsp)', function(obj) {
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
            id=obj.data.invCheckDescId;
            ypproId=obj.data.proId;
            inveDescBatchNum=obj.data.inveDescBatchNum;
            inveDescValidityDate=getTimeDate(obj.data.inveDescValidityDate);
            inveDescInventoryNum=obj.data.inveDescInventoryNum;
            $('#bh').val(obj.data.proId);
            $('#mc').val(obj.data.invCheckDescProName);
            $('#dw').val(obj.data.invCheckDescProUnit);
            $('#xh').val(obj.data.invCheckDescModel);
            $('#lx').val(postil);
            $('#kc').val(obj.data.invCheckDescInventoryNum);
            $('#cs').val(obj.data.invCheckDescManufacturer);
        })
        //修改数量
        $('#amend').click(function () {
            sta=0;
            entryGoods();
            if(sta==0){
                table.reload('inventoryInformation',{
                    url:"/searchDescId?proId="+ypproId,
                })
                table.reload('inventoryInformationNum',{
                    url:"/searchDescIdd?proId="+ypproId,
                })
            }
        })
        $(document).on('click','#inventpry',function() {
            newInventory()
            $("#stochasticpd").html(createSalesOrdId());
        })
        function newInventory() {
            layer.open({
                type: 1,
                title: '<h4 style="color: #1E9FFF;font-weight: bold;">录入盘点商品<h4>',
                scrollbar: false, //屏蔽浏览器滚动条
                area: ['100%', '100%'],
                content: $('#newInventory'),
            });
        }
        function entryGoods() {
            layer.open({
                type: 1,
                title: '<h4 style="color: #1E9FFF;font-weight: bold;">商品库存信息<h4>',
                scrollbar: false, //屏蔽浏览器滚动条
                area: ['80%', '80%'],
                content: $('#entryGoods'),
            });
        }

		var invChId
		var checkid;
        $("#ts").click(function () {
            layer.close(layer.index);
        })
        //确定新增已盘商品
        $(document).on('click', '#increase', function() {
            $("#modules").attr("disabled",true);
            form.render('select');
            //盘点单号
             invChId=$('#stochasticpd').html();
            checkid=invChId;
            var chNum = "";
            for ( var i in checkNum ) {
                chNum += checkNum[i];
                if ( i != checkNum.length - 1 && checkNum.length >=2 ) {
                    chNum += ',';
                }
            }
            for(var i=0;i<inveInfo.length;i++){
                inveInfo[i].invCheckId = invChId;
                inveInfo[i].inveDescStartDate = layui.util.toDateString(inveInfo[i].inveDescStartDate , "yyyy-MM-dd");
                inveInfo[i].inveDescValidityDate = layui.util.toDateString(inveInfo[i].inveDescValidityDate , "yyyy-MM-dd");
            }
            //转成JSON字符串格式后去除 '[' 与 ']'
            inveInfo = JSON.stringify(inveInfo).replace('[','').replace(']','');
            //如果sta是1，进行增加，否则进行修改
            if(sta==1){
                //局部刷新进行操作
                $.ajax({
                    url: "/updateInvencheckDesc/" + inveInfo ,
                    type:'get',
                    success:function (data) {
                        layer.close(layer.index);
                        table.reload('ypsp', {
                            url:"/searchStatementyp?invChId="+checkid,
                            page: {
                                curr: 1
                            }, done: function (res, curr, count) {
                                $('.layui-table-view[lay-id="ypsp"]')
                                    .children('.layui-table-box')
                                    .children('.layui-table-body')
                                    .find('table tbody tr[data-index="0"]').click();
                            },

                        }, 'data');
                        return false;
                    }
                })
            }else{
                $.ajax({
                    url: "/updateCheckNum/" + inveInfo,
                    type: 'get',
                    success:function (data) {
                        layer.close(layer.index);
                        table.reload('ypsp', {
                            url:"/searchStatementyp?invChId="+checkid,
                            page: {
                                curr: 1
                            }, done: function (res, curr, count) {
                                $('.layui-table-view[lay-id="ypsp"]')
                                    .children('.layui-table-box')
                                    .children('.layui-table-body')
                                    .find('table tbody tr[data-index="0"]').click();
                            },

                        }, 'data');
                        return false;
                    }
                })
            }
        });
        var pdData=$("#test3").val();
        $("#tuichu").click(function () {
            var checkData=$("#test3").val();
            var comment=$("#comment").val();
            var module=$("#modules").find("option:selected").text();
            $.post("/updateInvenCheck",{checkData:checkData,depId:module,comment:comment,invChId:invChId},function (data) {

            })
        })

        $(document).on('click','#addsp', function() {
            newInventory()
            $('#stochasticpd').html(checkid)
        });
		var id;


        $("#dele").click(function () {
                layer.confirm('是否删除商品', function (index) {
                    $.post("/updateCheckDescIdupdateCheckDescId",{id:id},function (data) {
                        layer.close(index);
                        table.reload('ypsp', {
                            page: {
                                curr: 1
                            }
                        }, 'data');
                        return false;
                    })
                });
        })


        $('#fixedInventory').click(function () {
           // layer.confirm('建议在修正库存前先备份数据库，以免数据丢失，现在就对库存进行修正吗', function (index) {
                $.ajax({
                    url: "/updateInvenDesc/" + descInfo ,
                    type:'get'
                })
            $.post("/updateInvenCheckId",function (data) {
            })
            //插入变动
            $.ajax({
                url: "/updateBreakage",
                type:'get'
            });
            //});
        });
        $.ajax({
            url:'/showProductTypeInfo',
            success:function (data) {
                var treeData = JSON.parse(data);
                treeData[0].spread = true;
                tree.render({
                    elem: '#test4',
                    data: treeData,
                    click:function (obj) {
                        var typeName = obj.data.id;
                        table.reload('spllxx',{
                            url:'/searchInventoryCollectInfo',
                            where:{
                                inveDescType:typeName,
                                inveDescDepot:$("#modules").val()
                            },
                            page:{curr:1}
                        },'data');
                    }
                })
            }
        });
    });
</script>
</body>

</html>
